// 采购订单相关类型定义

// 返回码枚举
export enum ResultCode {
    Success = 200,
    Fail = 500
}

// 采购订单状态枚举
export enum PurchaseOrderStatus {
    Draft = '草稿',           // 草稿
    Submitted = '已提交',   // 已提交
    PendingApproval = '待审批', // 待审批
    InApproval = '审批中', // 审批中
    Approved = '已审批',     // 已审批
    Rejected = '驳回',     // 驳回
    Completed = '已完成',   // 已完成
    Cancelled = '已取消'    // 已取消
}

// 结算方式枚举
export enum SettlementMethod {
    Cash = '现金',             // 现金
    BankTransfer = '银行转账', // 银行转账
    Check = '支票',           // 支票
    Credit = '信用',         // 信用
    Other = '其他'            // 其他
}

// 税率枚举
export enum TaxRate {
    Zero = 0,      // 0%
    Three = 3,     // 3%
    Six = 6,       // 6%
    Nine = 9,      // 9%
    Thirteen = 13  // 13%
}

// 采购订单基础信息
export interface PurchaseOrder {
    id: number
    orderSubject: string
    purchaseOrderNumber: string
    isSystemNumber: boolean
    relatedSalesOrder?: string
    doNotBindSalesOrder: boolean
    supplierId: number
    supplierName?: string
    contactPhone?: string
    purchasingDepartmentId?: number
    purchasingDepartmentName?: string
    relatedProjectId?: number
    relatedProjectName?: string
    deliveryAddress?: string
    remarks?: string
    relatedPurchaseRequest?: string
    doNotBindPurchaseRequest: boolean
    purchaseDate: string
    contactPerson?: string
    purchaserId?: number
    purchaserName?: string
    contactMethod?: string
    settlementMethod?: string
    orderStatus: string
    approvalProcessId?: number
    currentApprovalNode?: string
    createdBy: number
    createdByName?: string
    createdAt: string
    lastModifiedBy?: number
    lastModifiedByName?: string
    lastModifiedAt?: string
    details?: PurchaseOrderDetailItem[]
    totalAmountIncludingTax?: number
    totalAmountExcludingTax?: number
}

// 采购订单明细
export interface PurchaseOrderDetailItem {
    id: number
    purchaseOrderId: number
    serialNumber: number
    itemNumber: string
    itemName: string
    specificationModel?: string
    unit?: string
    brand?: string
    purchaseQuantity: number
    mainUnitQuantity: number
    taxRate: number
    unitPriceIncludingTax: number
    unitPriceExcludingTax: number
    amountIncludingTax: number
    amountExcludingTax: number
}

// 采购订单DTO（用于列表显示）
export interface PurchaseOrderDto extends PurchaseOrder {
    // 继承自PurchaseOrder，包含所有主表信息和明细列表
}

// 采购订单详情DTO
export interface PurchaseOrderDetailDto extends PurchaseOrderDto {
    details: PurchaseOrderDetail[]
    attachments?: PurchaseOrderAttachment[]
}

// 采购订单附件
export interface PurchaseOrderAttachment {
    id: number
    purchaseOrderId: number
    fileName: string
    fileSize: number
    filePath: string
    uploadTime: string
    uploadBy?: string
}

// 新增采购订单命令
export interface CreatePurchaseOrderCommand {
    orderSubject: string
    isSystemNumber: boolean
    purchaseOrderNumber?: string
    relatedSalesOrder?: string
    doNotBindSalesOrder: boolean
    supplierId: number
    contactPhone?: string
    purchasingDepartmentId?: number
    relatedProjectId?: number
    deliveryAddress?: string
    remarks?: string
    relatedPurchaseRequest?: string
    doNotBindPurchaseRequest: boolean
    purchaseDate: string
    contactPerson?: string
    purchaserId?: number
    contactMethod?: string
    settlementMethod?: string
    details: CreatePurchaseOrderDetailCommand[]
    attachments?: PurchaseOrderAttachment[]
}

// 新增采购订单明细命令
export interface CreatePurchaseOrderDetailCommand {
    serialNumber: number
    itemNumber: string
    itemName: string
    specificationModel?: string
    unit?: string
    brand?: string
    purchaseQuantity: number
    mainUnitQuantity: number
    taxRate: number
    unitPriceIncludingTax: number
    unitPriceExcludingTax: number
    amountIncludingTax?: number
    amountExcludingTax?: number
}

// 更新采购订单命令
export interface UpdatePurchaseOrderCommand {
    id: number
    orderSubject: string
    isSystemNumber: boolean
    purchaseOrderNumber?: string
    relatedSalesOrder?: string
    doNotBindSalesOrder: boolean
    supplierId: number
    contactPhone?: string
    purchasingDepartmentId?: number
    relatedProjectId?: number
    deliveryAddress?: string
    remarks?: string
    relatedPurchaseRequest?: string
    doNotBindPurchaseRequest: boolean
    purchaseDate: string
    contactPerson?: string
    purchaserId?: number
    contactMethod?: string
    settlementMethod?: string
    details: UpdatePurchaseOrderDetailCommand[]
    attachments?: PurchaseOrderAttachment[]
}

// 更新采购订单明细命令
export interface UpdatePurchaseOrderDetailCommand {
    id?: number
    purchaseOrderId?: number
    serialNumber: number
    itemNumber: string
    itemName: string
    specificationModel?: string
    unit?: string
    brand?: string
    purchaseQuantity: number
    mainUnitQuantity: number
    taxRate: number
    unitPriceIncludingTax: number
    unitPriceExcludingTax: number
    amountIncludingTax?: number
    amountExcludingTax?: number
}

// 删除采购订单命令
export interface DeletePurchaseOrderCommand {
    id: number
}

// 获取采购订单列表查询
export interface GetPurchaseOrderListQuery {
    pageIndex: number
    pageSize: number
    orderSubject?: string
    purchaseOrderNumber?: string
    supplierId?: number
    orderStatus?: string
    purchaseDateStart?: string
    purchaseDateEnd?: string
    createdBy?: number
}

// 获取采购订单详情查询
export interface GetPurchaseOrderByIdQuery {
    id: number
}

// API结果封装
export interface APIResult<T> {
    code: ResultCode
    message: string
    token?: string
    refreshToken?: string
    data: T
}

// 分页对象
export interface APIPageing<T> {
    pageIndex: number
    pageSize: number
    totalCount: number
    totalPages: number
    pageData: T[]
}

// 采购订单列表响应
export interface PurchaseOrderListResponse {
    code: ResultCode
    message: string
    data: APIPageing<PurchaseOrderDto>
}

// 采购订单详情响应
export interface PurchaseOrderDetailResponse {
    code: ResultCode
    message: string
    data: PurchaseOrderDetailDto
}

// 操作结果响应
export interface OperationResultResponse {
    code: ResultCode
    message: string
    data: boolean
}

// 新增采购订单响应
export interface CreatePurchaseOrderResponse {
    code: ResultCode
    message: string
    data: number
}

// 详情页-入库记录行
export interface InboundRecordRow {
    id: number
    inboundOrderNumber: string
    inboundOrderSubject: string
    inboundDate: string
    inboundType: string
    supplierName: string
    totalInboundQuantity: number
    inboundAmount: number
    inboundPersonnelName: string
}

// 详情页-付款记录行
export interface PaymentRecordRow {
    id: number
    paymentNumber: string
    paymentSubject: string
    paymentDate: string
    payee: string
    paymentAmount: number
    bankAccountNumber: string
}

// 详情页-到票记录行
export interface InvoiceRecordRow {
    id: number
    invoiceNumber: string
    invoiceSubject: string
    invoiceDate: string
    issuer: string
    invoiceType: string
    invoiceCode: string
}

// 详情页-检验记录行
export interface InspectionRecordRow {
    id: number
    inspectionNumber: string
    inspectionSubject: string
    inspectionDate: string
    inspector: string
    itemsSummary: string
    remarks?: string
}

// 详情页-退货记录行
export interface ReturnRecordRow {
    id: number
    outboundNumber: string
    outboundSubject: string
    outboundDate: string
    outboundType: string
    supplierName: string
    totalOutboundQuantity: number
    outboundAmount: number
}

// 详情页-审批步骤行
export interface ApprovalStepRow {
    id: number
    nodeName: string
    handlerName: string
    status: string
    receivedAt?: string
    submittedAt?: string
}

// 详情页-操作记录行
export interface OperationRecordRow {
    id: number
    operatorName: string
    operationTime: string
    operationContent: string
}

// 与后端 SimplePaged 结构对齐（字段与 APIPageing 相同，可互换）
export type SimplePaged<T> = APIPageing<T> 